package core.bmp.utils;

import core.bmp.model.Pixel;

public class PixelUtil {
	
	/* 数据转化 */
	
	public static Pixel intToPixel(int argb) {
		byte[] bytes = IntegerUtil.intToBytes(argb);
		// 由于是大端序，所以alpha在3的位置
		return new Pixel(bytes[3], bytes[2], bytes[1], bytes[0]);
	}
	
	public static int pixelToInt(Pixel pixel) {
		return IntegerUtil
				.bytesToInt(new byte[] { pixel.getBlue(), pixel.getGreen(), pixel.getRed(), pixel.getAlpha() });
	}
	
	/* 灰度 */

	public static void setGray(Pixel pixel, byte gray) {
		pixel.setRed(gray);
		pixel.setGreen(gray);
		pixel.setBlue(gray);
	}
	
	public static Pixel createGrayPixel(byte gray) {
		return new Pixel((byte) 0xFF, gray, gray, gray);
	}
	
	public static int createGrayArgb(byte gray) {
		return IntegerUtil.bytesToInt(new byte[] { gray, gray, gray, (byte) 0xFF, });
	}
	
}
